<?php
class Login extends CI_Controller {
  
    public function __construct(){
        parent::__construct();
        $this->load->helper("url");
        $this->load->library(array("form_validation","session","my_auth"));
         $this->load->database();
        $this->load->model("Mregister");

    }
		
	public function index(){

		if($this->my_auth->is_LoginTrue())
        {
            redirect(base_url()."dang-nhap");
            exit();
        }
        else {
        	// redirect(base_url()."dang-ky");
        	//  exit();
        }


			$temp['title'] = 'Tuyển dụng và đào tạo';
			$temp['template'] = 'frontend/_blocks/login';
         	
			$this->load->view("frontend/_layout/default", $temp);

	


/*if($this->my_auth->is_LoginTrue())
        {
            redirect(base_url()."dang-nhap");
            exit();
        }
        $u = $this->input->post("txtemail");
	    $p = $this->input->post("password");
	    $session = $this->Mregister->checkLogin($u,$p);*/



	}

	public function isLogging(){

		$u = $this->input->post("txtemail");
	    $p = $this->input->post("password");
	    $session = $this->Mregister->checkLogin($u,$p);
	 
	     if($session)
             {
           
                 if(!$this->my_auth->is_Active($session['id'])){
                   		$temp['template'] = 'frontend/news/index';
						$this->load->view("frontend/_layout/default", $temp);
                 }
                 else
                 {
                      $data = array(
                                    "username"  => $session['email'],
                                    "userid"    => $session['id'],
                                    "level"  => $session['level'],
                                );
                                
                     $this->my_auth->set_userdata($data);
                    // redirect(base_url()."tin-tuc");
                 }
                 
             }
             else
             {  
               // $this->load->view("backend/login",array("error"=>"Username or Password wrong"));    
             }


	}


	 function logout()
    {
        $this->my_auth->sess_destroy();
		redirect(base_url());
    }


}